const mix = require('laravel-mix');
const WebpackBar = require("webpackbar");
const date = require("dayjs")().format("YYYY_M_D");
const time = require("dayjs")().format("YYYY-M-D HH:mm:ss");
const path = require("path");
const resolve = ( dir ) => {
    return path.resolve(__dirname, dir)
}
const baseUrl = 'resources/src';

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.webpackConfig(Webpack => {
    return {
        resolve: {
            alias: {
                '@': resolve(baseUrl),
                '^': resolve(baseUrl+'/components'),
                'v': resolve(baseUrl+'/views')
            },
        },
        plugins: [
            new Webpack.DefinePlugin({
                "process.env.VUE_APP_UPDATE_TIME": "'" + time + "'",
            }),
            new WebpackBar({
                name: `\u0076\u0075\u0065\u002d\u0061\u0064\u006d\u0069\u006e\u002d\u0062\u0065\u0061\u0075\u0074\u0069\u0066\u0075\u006c`,
            })
        ]
    };
});

Mix.listen('configReady', (webpackConfig) => {
    webpackConfig.module.rules.push({
        test: /\.s[ac]ss$/i,
        use: [
            'sass-loader',
            {
                loader: 'sass-resources-loader',
                options: {
                    resources: [
                        resolve(baseUrl+'/styles/variables.scss')
                    ]
                },
            },
        ],
    },{
        // rule:'remixIcon',
        test: /\.svg$/,
        loader: 'svg-sprite-loader',
        include: resolve(baseUrl+'/remixIcon'),
        options: {
            symbolId: 'remix-icon-[name]',
        }
    }, {
        // rule:'colorfulIcon',
        test: /\.svg$/,
        loader: 'svg-sprite-loader',
        include: resolve(baseUrl+'/colorfulIcon'),
        options: {
            symbolId: 'colorful-icon-[name]',
        }
    });
    let fontLoaderConfig = webpackConfig.module.rules.find(rule => String(rule.test) === String(/(\.(woff2?|ttf|eot|otf)$|font.*\.svg$)/) || String(rule.test) === String(/(\.(png|jpe?g|gif|webp)$|^((?!font).)*\.svg$)/));
    fontLoaderConfig.exclude = [resolve(baseUrl+'/remixIcon'),resolve(baseUrl+'/colorfulIcon')];
});

mix.js('resources/src/main.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css')
    .autoload({
        jquery: ['$', 'window.jQuery']
    });


if (mix.inProduction()) {
    mix.version();
}else{
    mix.disableNotifications()
}
